#!/bin/bash

set -o errexit

test_dir=$(realpath $(dirname $0))
. ${test_dir}/../functions

set_debug

check_cr_config() {
	local cluster="$1"

	desc "apply cr config"
	spinup_pxc "$cluster" "$test_dir/conf/$cluster.yml"

	desc "check if statefulset created with expected config"
	compare_kubectl statefulset/$cluster-pxc
	compare_kubectl statefulset/$cluster-proxysql

	desc "delete cluster"
	kubectl_bin delete \
		-f $test_dir/conf/$cluster.yml
}

main() {
    create_infra $namespace

    apply_config "$conf_dir/client.yml"
    kubectl_bin apply \
        -f $conf_dir/secrets.yml \
        -f $test_dir/conf/hostpath-helper.yml

	desc 'check emptydir'
	check_cr_config "emptydir"

	desc 'check hostpath'
	check_cr_config "hostpath"

	destroy $namespace
	desc "test passed"
}

main
